import types from './types'
import { Fetch } from '@/utils/http_common'

const actions = {
	// 获取审核用户的列表
	setAduitUser({ commit, rootGetters }) {
		Fetch.get('companies/' + rootGetters.current_user.company_id + '/fetch_nodes').then(res => {
			console.log(res)
			let list = []
			res.nodes.map(item => {
				item.users_info.map(item => {
					list.push(item)
				})
			})
			commit(types.SET_ADUIT_USERS, list)
		}).catch(error => {
			console.log(error)
		})
	},
	//获取销售人员列表
	getSaleList({ commit, rootGetters }){
		Fetch.get('users/manager').then(res => {
			let list = []
			res.users.map(item => {
				list.push(item)
			})
			commit(types.SET_ADUIT_USERS, list)
		}).catch(error => {
			console.log(error)
		})
	},
	//删除审核人
	delectAduitUser({ commit, rootGetters }, params){
		Fetch.get('companies/' + rootGetters.current_user.company_id + '/edit_node',params).then(res=>{
			console.log(res)
		})
	},
	// 设置品牌下的部门和角色
	setDepartmentAndRole({ commit, rootGetters }) {
		Fetch.get(
				'companies/' +
				rootGetters.current_user.company_id +
				'/fetch_department_roles'
			)
			.then(res => {
				commit(types.SET_DEPARTMENT_AND_ROLE, res.departments)
			})
			.catch(error => console.log(error))
	}
}

export default actions